package com.cal.calendar;

import android.app.Activity;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

public class TitleGridViewAdapter extends BaseAdapter {

	// 上面的标题名称
	int[] titles = new int[] { R.string.sunday, R.string.monday,
			R.string.tuesday, R.string.wednesday, R.string.thursday,
			R.string.friday, R.string.saturday };

	private Activity activity;

	public TitleGridViewAdapter(Activity a) {
		activity = a;
	}

	@Override
	public int getCount() {
		return titles.length;
	}

	@Override
	public Object getItem(int position) {
		return titles[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		LinearLayout weekCell = new LinearLayout(activity);
		TextView weekCellUnion = new TextView(activity);
		weekCellUnion.setFocusable(false);
		weekCellUnion.setBackgroundColor(Color.TRANSPARENT);
		weekCell.setOrientation(1);

		weekCellUnion.setGravity(Gravity.CENTER);
		
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
				LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

		int i = (Integer) getItem(position);

		weekCellUnion.setTextColor(Color.WHITE);

		if (i == R.string.saturday || i == R.string.sunday) {
			// 周六
			weekCellUnion.setBackgroundColor(Color.MAGENTA);
		}

		weekCellUnion.setText((Integer) getItem(position));

		weekCell.addView(weekCellUnion, params);

		return weekCell;
	}
}
